package stateDiagram.figures;

import static org.jhotdraw.draw.AttributeKeys.FILL_COLOR;
import static org.jhotdraw.draw.AttributeKeys.STROKE_COLOR;

import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;

import org.jhotdraw.draw.EllipseFigure;
import org.jhotdraw.draw.Figure;
import org.jhotdraw.draw.GraphicalCompositeFigure;


import org.jhotdraw.draw.ListFigure;
import org.jhotdraw.geom.Dimension2DDouble;
import org.jhotdraw.geom.Insets2D;
import org.jhotdraw.xml.DOMInput;
import org.jhotdraw.xml.DOMOutput;

import stateDiagram.EntityObjects.StateEntity;

public class EndStateFigure extends GraphicalCompositeFigure{
	private StateEntity stateEntity;
	
	public EndStateFigure(){
		super();
		
		stateEntity = new StateEntity("end", null, null);
      
		EllipseFigure endOuter = new EllipseFigure();
		endOuter.set(FILL_COLOR, Color.WHITE);
	    endOuter.setAttributeEnabled(FILL_COLOR, true);
	    ListFigure list =  new ListFigure(endOuter);
	    add(list);
	   
	 	EllipseFigure endInner = new EllipseFigure();
	 	Insets2D.Double insets = new Insets2D.Double(4, 4, 4, 4);
	    endInner.set(LAYOUT_INSETS, insets);
		endInner.set(FILL_COLOR, Color.BLACK);
	    endInner.setAttributeEnabled(FILL_COLOR, true);
	    list.add(endInner);
		
	}
	
	public StateEntity getStateEntity(){
		return stateEntity;
	}
	
    public void setBounds(Point2D.Double anchor, Point2D.Double lead) {
    	super.setBounds(anchor,new Point2D.Double( anchor.x +16, anchor.y +16));
    }
    
    public void read(DOMInput in) throws IOException {
    	 double x = in.getAttribute("x", 0d);
         double y = in.getAttribute("y", 0d);
        // double w = in.getAttribute("w", 0d);
        // double h = in.getAttribute("h", 0d);
         willChange();
         setBounds(new Point2D.Double(x, y), new Point2D.Double(x + 16, y + 16));
       ((ListFigure) getChild(0)).getChild(0).setBounds(new Point2D.Double(x,y), new Point2D.Double(x + 16, y +16));
       changed();
    }

    @Override
    public void write(DOMOutput out) throws IOException {
    	Rectangle2D.Double r = getBounds();
        out.addAttribute("x", r.x);
        out.addAttribute("y", r.y);
        writeAttributes(out);  
    }
	

}
